package com.bit.IO;

import java.io.*;

public class IOTest5 {
    public static void main(String[] args) {
        copy();
    }
    private static void copy(){
        try(FileReader fileReader = new FileReader("d:/test/1234.jpg");
            FileWriter fileWriter = new FileWriter("d:/test/12345.jpg")){
            char[] buffer = new char[1024];
            int len = -1;
            while((len = fileReader.read(buffer)) !=-1){
                fileWriter.write(buffer,0,len);
            }
        }catch (IOException e){
            e.printStackTrace();
        }
    }
    private static void copyFile2() {
        try (BufferedReader bufferedReader = new BufferedReader(new FileReader("d:/test/1234.jpg"));
             BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("d:/test/12345.jpg"))) {
            char[] buffer = new char[1024];
            int len = -1;
            while ((len = bufferedReader.read(buffer)) != -1) {
                bufferedWriter.write(buffer, 0, len);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
